[#include "/includes/_layout.html"/]
<title>添加|编辑微页面分类</title>
[@layout]
<div class="wrapper wrapper-content">
	<div class="row animated fadeInLeft">
	
	[#include "/includes/menu-store.html" /]
	
	<div class="col-sm-11">
	<div class="row content-tabs">
		<div class="row content-tabs">
		<nav class="page-tabs J_menuTabs">
	       <div class="page-tabs-content" style="margin-left: 0px;">
	           <a href="${webctx}/weipage" class="J_menuTab">微页面</a>
		       <a href="${webctx}/weipage/cat" class="J_menuTab  active">分类</a>
	       </div>
	   	</nav>
	</div>
	</div>
	<div class="ibox float-e-margins">
		<div class="ibox-title row">
			<h5><small><a href="${webctx}/weipage/cat">《返回列表</a></small></h5>
		</div>
		<div class="row ibox-content active_statistics">
			<div class="title_query padtop"> 
			<form id="qiandaoForm" class="form-horizontal">
			      <input type="hidden" id="id" value="${category.id}" class="input-xfat"  name="id"  >
				  <div class="form-group">
			            <label class="col-md-2 control-label">分类名称<span style="color: red;"><em>*</em></span></label>
			            <div class="col-md-8" id="error_name">
			            	
			                <input id="name" name="name" value="${category.name }" maxlength="20" type="text" class="form-control" style="width: 200px" >
			                <label class="control-label" for="name"></label>
			            </div>
			        </div>

			        <div class="form-group">
			            <label class="col-md-2 control-label">排序<span style="color: red;"><em>*</em></span></label>
			            <div class="col-md-2" id="error_orders">
			                <input id="orders" name="orders" value="${category.orders }" maxlength="20" type="text" class="form-control"  onkeyup="this.value=this.value.replace(/\D/g,'')">
			                <label class="control-label" for="error_orders"></label>
			            </div>
			        </div>
				</form>
			</div>
		</div>
	</div>
	
	<div class="panel-footer" align="center">
   	 	<button onclick="saveCategory();" class="btn btn-sm btn-success"><i class="fa fa-dot-circle-o"></i>提交</button>
	</div>
</div>
</div>
</div>
[/@layout]
<script type="text/javascript">
function saveCategory(){
	var params = {},error = {};	
	var categoryId = $("#id").val(), 
	categName = $("#name").val(), categOrder = $("#orders").val();
	if(categoryId!=null && categoryId!="") params.id = categoryId;

	if($.trim(categName) =="") {error.error_name = "分类名称不能为空"; } else {error.error_name=""; params.name = $.trim(categName);}
	if($.trim(categOrder) =="") {error.error_orders = "分类排序不能为空"; } else {error.error_orders =""; params.orders = $.trim(categOrder);}
	var hasError = false;
	for(var key in error){
		if(error[key]!=""){
			if(!hasError) hasError = true;
			$("#"+key).addClass("has-error");
			$("#"+key).find("label").text(error[key]);
		}else{
			$("#"+key).removeClass("has-error");
			$("#"+key).find("label").empty();
		}
	}
	//主表信息不完整，返回
	if(hasError) return false;
	
	$.post(obz.ctx+"/weipage/cat/save", params, function(resp) {
		if(resp.code == 200){
			location.href = "${webctx}/weipage/cat";
		}
	});
}
</script>
<script>
Template.init("#menu-shop");
Template.initSecond("#menu-weipage");
</script>